<template>
  <div>
    <div style="height: 507px; width: 500px; padding: 0 20px">
      <el-form
        ref="formRef"
        :model="saveParams"
        :disabled="isView"
        :rules="rules"
        label-position="top"
      >
        <el-form-item prop="earlyWarnStatus">
          <template #label>
            启用预警退货
            <span style="color: red"
              >* (启动后，系统根据包裹签收状态，到达预计天数自动退货）</span
            >
          </template>
          <el-select
            v-model="saveParams.earlyWarnStatus"
            placeholder="启用预警退货"
            style="width: 100%"
            clearable
          >
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <template #label>
            预警天数
            <span style="color: red"
              >(包裹签收后，到达预警天数后会进行商品提醒）</span
            >
          </template>
          <el-input
            v-model="saveParams.earlyWarnDay"
            placeholder="预警天数"
            @input="
              saveParams.earlyWarnDay = limitIntNumber(saveParams.earlyWarnDay)
            "
            clearable
          />
        </el-form-item>
        <el-form-item>
          <template #label>
            退货天数
            <span style="color: red"
              >(包裹签收后，到达退货天数后会商品会自动退货）</span
            >
          </template>
          <el-input
            v-model="saveParams.returnDay"
            placeholder="预警天数"
            @input="saveParams.returnDay = limitIntNumber(saveParams.returnDay)"
            clearable
          />
        </el-form-item>
      </el-form>
    </div>
    <div class="dFooter">
      <span class="dialog-footer">
        <el-button type="primary" v-if="!isView" @click="clickSave">
          提交
        </el-button>
        <el-button @click="handleClose">关闭</el-button>
      </span>
    </div>
  </div>
</template>

<script setup>
import { getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const props = defineProps({
  detailData: { type: Object },
  isView: { type: Boolean },
});
let saveParams = ref({});
onMounted(() => {
  if (JSON.stringify(props.detailData) != "{}") {
    saveParams.value = props.detailData.header;
  }
});
// 表单校验
const rules = ref({
  earlyWarnStatus: [
    { required: true, message: "启用预警退货不能为空", trigger: "change" },
  ],
});

const emits = defineEmits(["cancel", "setReturnWarn"]);

function handleClose() {
  emits("cancel");
}

// function clickNext() {
//   proxy.$refs.formRef.validate((valid, fileds) => {
//     if (valid) {
//       emits("setReturnWarn", saveParams.value);
//     }
//   });
// }

function clickSave() {
  // if(tableList.value.length>0){
  //   emits('clickSave',tableList.value)
  // }else {
  //   proxy.$modal.msgWarning("请先关联SKU!")
  // }
  proxy.$refs.formRef.validate((valid, fileds) => {
    if (valid) {
      emits("clickSave", saveParams.value);
    }
  });
}

function getData() {
  return saveParams.value;
}

defineExpose({
  getData,
});
</script>

<style scoped lang="scss">
.dFooter {
  width: 100%;
  display: flex;
  justify-content: right;
}
</style>
